package com.goodedeeds.domain.resource;

import com.goodedeeds.domain.IVendorCategory;
import com.youtills.core.admin.ILookup;
import com.youtills.core.admin.ILookupType;
import com.youtills.core.admin.LookupType;
import com.youtills.core.admin.db.dao.AdminDao;
import com.youtills.resource.BaseResource;
import com.youtills.resource.CommonAttribute;
import com.youtills.resource.ResourceAttributeValue;

/**
 * Created by IntelliJ IDEA.
 * User: rchiluve
 * Date: 2/23/14
 * Time: 7:48 PM
 * To change this template use File | Settings | File Templates.
 */
public class VendorCategory extends BaseResource implements IVendorCategory {

//    private int vendorCategoryId;

    private final ResourceAttributeValue<String> categoryName;
    private final ResourceAttributeValue<String> categoryDescription;
    private final ILookupType lookupType;

    public VendorCategory() {
        super();
        //TODO - set appropriate resource type.
//        setResourceType(0);
        lookupType = LookupType.getByType(10L);
        this.categoryName = new ResourceAttributeValue<>(this, CommonAttribute.name);
        this.categoryDescription = new ResourceAttributeValue<>(this, CommonAttribute.description);

    }

    public Long getCategoryId() {
        return getResourceId();
    }

    public void setCategoryId(Long schoolId) {
        //setResourceId(schoolId);
    }

    public String getCategoryName() {
        if(categoryName == null  && lookupType != null){
            ILookup lookup = AdminDao.getInstance().getLookup(lookupType, getCategoryId());
            if(lookup != null){
                categoryName.setValue(lookup.getName());
                categoryDescription.setValue(lookup.getDescription());
            }
        }
        return categoryName.getValue();
    }

    public String getCategoryDescription() {
        return categoryDescription.getValue();
    }

    @Override
    protected String getTableName() {
        return null;
    }
}
